package com.sgb.kjwl.view.widget;

import android.content.Context;
import android.graphics.Paint;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.GasListInfoEntity;
import com.swgk.core.dialog.BasePopWindow;
import com.swgk.core.dialog.PopViewHolder;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

public class MapGasPopWindow extends BasePopWindow {

    List<GasListInfoEntity> mdatas=new ArrayList<>();
    private TextView tvFree,tvDistance,tvPice,tvPice1,tv_name,tv_adress;


    public void setMdatas(List<GasListInfoEntity> mdatas) {
        this.mdatas = mdatas;
    }

    public MapGasPopWindow(Context context) {
        super(context, DIR_DOWN_UP);
    }

    @Override
    protected int popLayout() {
        return R.layout.item_gas_list;
    }

    @Override
    protected void initView(PopViewHolder holder) {
        tv_name=holder.itemView.findViewById(R.id.tv_name);
         tvFree=holder.itemView.findViewById(R.id.tv_free);
         tvDistance=holder.itemView.findViewById(R.id.tv_distance);
         tvPice=holder.itemView.findViewById(R.id.tv_price2);
         tvPice1=holder.itemView.findViewById(R.id.tv_price);
        tv_adress=holder.itemView.findViewById(R.id.tv_adress);

    }
    public void setData(GasListInfoEntity infoEntity){
        if(!TextUtils.isEmpty(infoEntity.getFavouredPolicy())){
            tvFree.setVisibility(View.VISIBLE);
            tvFree.setText(infoEntity.getFavouredPolicy());
        }else{
            tvFree.setVisibility(View.GONE);

        }
        tvDistance.setText(m1(Double.valueOf(infoEntity.getDistance())/1000)+"km");
        tvPice.setText("标准价¥"+infoEntity.getStandardPrice());
        tvPice1.setText("¥"+infoEntity.getPrice());
        tvPice.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
        tv_name.setText(infoEntity.getGasStationName());
        tv_adress.setText(infoEntity.getGasStationAddress());

    }
    /**
     * BigDecimal转double 四舍五入保留两位小数
     */
    public double m1(double num) {
        BigDecimal bg = new BigDecimal(num);
        double f1 = bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
        return f1;
    }
}
